package com.example.springboot.pattern.observer;

public class ConcreteObserver implements Observer {
    private String name;
    private ConcreteSubject subject;

    public ConcreteObserver(String name, ConcreteSubject subject) {
        this.name = name;
        this.subject = subject;
        subject.addObserver(this);
    }

    @Override
    public void update(Subject subject) {
        if (subject instanceof ConcreteSubject) {
            System.out.println(name + " received update: " + ((ConcreteSubject) subject).getState());
        }
    }
}
